﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using BusinessObject;

namespace GreenLife
{
    public partial class Default : System.Web.UI.Page
    {
        NewsBO nBO = new NewsBO();
        GreenLifesBO glBO = new GreenLifesBO();
        DataSet ds, ds1, ds2;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.selectNewsByStatus();
            }
        }
        public void selectNewsByStatus()
        {
            //tin tuc
            ds = nBO.getTopNewByStatus(1);
            this.listNewsTinTuc.DataSource = ds.Tables[0];
            this.listNewsTinTuc.DataBind();

            //Tien do
            ds1 = nBO.getTopNewByStatus(2);
            this.listTDDefault.DataSource = ds1.Tables[0].DefaultView;
            this.listTDDefault.DataBind();

            //Tien ich
            ds2 = glBO.getTopGreenLifeByStatus(3);
            this.listTienIch.DataSource = ds2.Tables[0].DefaultView;
            this.listTienIch.DataBind();
        }
        protected void rpt_TinTuc_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            Repeater rpt_Con = (Repeater)e.Item.FindControl("rpt_Con");//lay rpt_con
            DataRowView dr = (DataRowView)e.Item.DataItem;

            if (rpt_Con != null)
            {
                ds = nBO.getTitleByStatus(1);
                rpt_Con.DataSource = ds.Tables[0];
                rpt_Con.DataBind();
            }
        }

        protected void rpt_TienDo_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            Repeater rpt_Con = (Repeater)e.Item.FindControl("rpt_Con");//lay rpt_con
            DataRowView dr = (DataRowView)e.Item.DataItem;

            if (rpt_Con != null)
            {
                ds = nBO.getTitleByStatus(2);
                rpt_Con.DataSource = ds.Tables[0];
                rpt_Con.DataBind();
            }
        }

        protected void rpt_TienIch_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            Repeater rpt_Con = (Repeater)e.Item.FindControl("rpt_Con");//lay rpt_con
            DataRowView dr = (DataRowView)e.Item.DataItem;

            if (rpt_Con != null)
            {
                ds = glBO.getGreenLifeByStatus(3);
                rpt_Con.DataSource = ds.Tables[0];
                rpt_Con.DataBind();
            }
        }
    }
}